import axios from "axios"
const instance = axios.create({
  baseURL:'/api'
    // baseURL:"http://520it.com:8881/cms"
    // baseURL:"http://kumanxuan1.f3322.net:8881/cms"
})
export default instance

// 请求拦截器
instance.interceptors.request.use(function (config) {
    console.log("请求拦截器");
    let mytoken = localStorage.getItem("x-auth-token")
    
    if(mytoken){
      config.headers["x-auth-token"] = mytoken
    }
    return config;
  },error => {
    // Do something with request error
    return Promise.reject(error);
  });

// 响应拦截器
instance.interceptors.response.use(function (response) {
   console.log("响应拦截器",response);
   // 统一在此处提示错误信息
   if(response.data.code !=0 && response.data.code !=400 && response.data.code !=407){
     alert(response.data.msg);
     return false
   }
    return response.data;
    
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });